<template>
  <div class="home">
    <van-form ref="basicInfo" :disabled="oper === 'view'">
      <van-field
        v-model="obj.reimbursementCode"
        label="报账单号："
        placeholder="自动生成"
        readonly
        input-align="right"
      />
      <van-field
        v-model="obj.reimbursementDate"
        label="报账日期："
        placeholder="请选择日期"
        input-align="right"
        readonly
        required
        right-icon="arrow"
        :rules="[{ required: true, message: '请选择报账日期' }]"
        @click="isShowPickerDate = true"
      />
      <van-popup v-model:show="isShowPickerDate"  position="bottom">
        <van-date-picker v-model="currentDate1" type="date" @cancel="isShowPickerDate = false" @confirm="onConfirmDate1" />
      </van-popup>
      <van-field
        v-model="applicationOrganizationName"
        label="申请人部门："
        required
        placeholder="请选择"
        input-align="right"
        right-icon="arrow"
        :label-width="140"
        @click="showPicker1 = true"
      />
      <van-popup v-model:show="showPicker1" position="bottom">
        <van-picker
          :columns="organizationList"
          :columns-field-names="{text: 'organizationName', value: 'id'}"
          @cancel="showPicker1 = false"
          @confirm="onConfirmPicker1"
        />
      </van-popup>
      <van-field
        v-model="applicationUserName"
        label="申请人："
        readonly
        required
        placeholder="请选择"
        input-align="right"
        right-icon="arrow"
        :rules="[{ required: true, message: '请选择申请人' }]"
        @click="showPicker2 = true"
      />
      <van-popup v-model:show="showPicker2" round position="bottom">
        <van-picker
          :columns="userList"
          :columns-field-names="{text: 'name', value: 'id'}"
          @cancel="showPicker2 = false"
          @confirm="onConfirmPicker2"
        />
      </van-popup>
      <van-field
        v-model="obj.remark"
        rows="2"
        autosize
        label="摘要"
        type="textarea"
        input-align="right"
        placeholder="请输入摘要"
      />
      <van-field
        v-model.number="obj.amount"
        type="number"
        required
        label="请输入金额"
        input-align="right"
        :rules="[{ required: true, message: '请输入金额' }]"
      />
      <div class="select-list">
        <div class="list">
          <div class="list-content">
            <span>指标编码：</span>
            <span v-if="expenditureKpiObj.kpiCode">{{ expenditureKpiObj.kpiCode }}</span>
            <span v-else>暂无</span>
          </div>
          <div class="list-content">
            <span>指标名称：</span>
            <span v-if="expenditureKpiObj.kpiName">{{ expenditureKpiObj.kpiName }}</span>
            <span v-else>暂无</span>
          </div>
          <div class="list-content">
            <span>可用金额：</span>
            <span v-if="expenditureKpiObj.kpiCode">￥{{ expenditureKpiObj.availableAmount }}</span>
            <span v-else>暂无</span>
          </div>
          <div class="btns">
            <van-button plain type="primary" size="small" class="btn" @click="kpiVisible = true" :disabled="oper === 'view'">选择指标</van-button>
            <van-button plain type="primary" size="small" class="btn" :disabled="!expenditureKpiObj.kpiCode" @click="isShowModel = true">指标详情</van-button>
          </div>
        </div>
        <van-field
          v-model="expenditureEconomicName"
          is-link
          readonly
          :required="rulesExpenditureEconomicId"
          :disabled="!expenditureKpiObj.kpiCode || oper === 'view'"
          input-align="right"
          label="经济分类"
          placeholder="请选择经济分类"
          @click="isShowExpenditureEconomic = true"
          :rules="[{ required: rulesExpenditureEconomicId, message: '请选择经济分类' }]"
        />
        <van-popup v-model:show="isShowExpenditureEconomic" position="bottom">
          <van-cascader
            v-model="cascaderValue"
            title="请选择经济分类"
            :options="expenditureEconomicList"
            @close="isShowExpenditureEconomic = false"
            :field-names="{text: 'name', value: 'id'}"
            @finish="onFinish"
          />
        </van-popup>
        <div class="list">
          <div class="list-content">
            <span>申请单号：</span>
            <span v-if="expenditureApplicationObj.applicationCode">{{ expenditureApplicationObj.applicationCode }}</span>
            <span v-else>暂无</span>
          </div>
          <div class="list-content">
            <span>申请金额：</span>
            <span v-if="expenditureApplicationObj.amount">{{ expenditureApplicationObj.amount }}</span>
            <span v-else>暂无</span>
          </div>
          <div class="list-content">
            <span>可用金额：</span>
            <span v-if="expenditureApplicationObj.availableAmount">{{ expenditureApplicationObj.availableAmount }}</span>
            <span v-else>暂无</span>
          </div>
          <div class="btns">
            <van-button plain type="primary" size="small" class="btn" @click="kpiVisible1 = true" :disabled="oper === 'view'">选择事前申请单</van-button>
            <van-button plain type="primary" size="small" class="btn" :disabled="!expenditureApplicationObj.applicationCode" @click="isShowModel1 = true">事前申请单详情</van-button>
          </div>
        </div>
      </div>
      <div class="">
        <van-cell-group>
          <!-- <span  v-if="getEnv() === 'local' && available" style="padding-left: 1.25rem;padding: .9375rem 0">可用金额：￥{{ available }}</span> -->
          
          <van-field
            v-model="expenditureSubjectName"
            is-link
            readonly
            
            input-align="right"
            label="会计科目"
            placeholder="请选择会计科目"
            @click="isShowExpenditureSubject = true"
   
          />
          <van-popup v-model:show="isShowExpenditureSubject" position="bottom">
            <van-cascader
              v-model="cascaderValue1"
              title="请选择会计科目"
              :options="expenditureSubjectList"
              @close="isShowExpenditureSubject = false"
              :field-names="{text: 'name', value: 'id'}"
              @cancel="isShowExpenditureSubject = false"
              @finish="onFinish1"
            />
          </van-popup>
          <van-field
            v-model="settlementName"
            is-link
            readonly
            label="结算方式："
            placeholder="请选择"
            input-align="right"
            @click="showPicker3 = true"
          />
          <van-popup v-model:show="showPicker3" position="bottom">
            <van-picker
              :columns="getDictList('ExpenditureSettlement')"
              :columns-field-names="{text: 'value', value: 'key'}"
              @cancel="showPicker3 = false"
              @confirm="onConfirmPicker3"
            />
          </van-popup>
         

          
        </van-cell-group>
      </div>
    </van-form>
  </div>
  <van-popup v-model:show="isShowModel" :closeable="true" :style="{ height: '80%', width: '90%' }">
    <div class="model">
      <div class="model-head">指标单详情</div>
      <div class="model-content">
        <div class="content">
          <span>预算年度：</span>
          <span>{{ expenditureKpiObj.year }}</span>
        </div>
        <div class="content">
          <span>支出类型：</span>
          <span>
            <DictTag :dict-list="getDictList('ExpenditureKpiPayType')" :dict-key="expenditureKpiObj.payType" />
          </span>
        </div>
        <div class="content">
          <span>经费类型：</span>
          <span>
            <DictTag :dict-list="getDictList('ExpenditureKpiFundType')" :dict-key="expenditureKpiObj.fundType" />
          </span>
        </div>
        <div class="content">
          <span>预算总金额：</span>
          <span>￥{{ expenditureKpiObj.amount }}</span>
        </div>
        <div class="content">
          <span>可用金额：</span>
          <span>￥{{ expenditureKpiObj.availableAmount }}</span>
        </div>
        <div class="content">
          <span>项目负责人部门：</span>
          <span>{{ showIdLabel(organizationList, expenditureKpiObj.organizationId, 'organizationName') }}</span>
        </div>
        <div class="content">
          <span>项目负责人：</span>
          <span>{{ showIdLabel(userList, expenditureKpiObj.managerId, 'name') }}</span>
        </div>
        <div class="content">
          <span>功能分类：</span>
          <span>{{ showIdLabel(expenditureFunctionalList, expenditureKpiObj.expenditureFunctionalId, 'name') }}</span>
        </div>
        <div class="content">
          <span>财政项目：</span>
          <span>{{ showIdLabel(expenditureFiscalList, expenditureKpiObj.expenditureFiscalId, 'name') }}</span>
        </div>
        <div class="content">
          <span>指标来源：</span>
          <span>
            <DictTag :dict-list="getDictList('ExpenditureKpiSource')" :dict-key="expenditureKpiObj.source" />
          </span>
        </div>
        <div class="content">
          <span>项目类型：</span>
          <span>{{ showIdLabel(expenditurePtypeList, expenditureKpiObj.expenditurePtypeId, 'name') }}</span>
        </div>
        <div class="content">
          <span>指标单状态：</span>
          <span>
            <EnumTag :enum-list="getEnumList('ExpenditureKpiState')" :enum-key="expenditureKpiObj.state" />
          </span>
        </div>
        <div class="content">
          <span>按经济分类控制金额：</span>
          <span>
            <EnumTag :enum-list="getEnumList('CommonYesNo')" :enum-key="expenditureKpiObj.isEconomic" />
          </span>
        </div>
      </div>
    </div>
  </van-popup>
  <van-popup v-model:show="isShowModel1" :closeable="true" :style="{ height: '80%', width: '90%' }">
    <div class="model">
      <div class="model-head">事前申请单详情</div>
      <div class="model-content">
        <div class="content">
          <span>预算年度：</span>
          <span>￥{{ expenditureApplicationObj.year }}</span>
        </div>
        <div class="content">
          <span>支出类型：</span>
          <span>
            <DictTag :dict-list="getDictList('ExpenditureKpiPayType')" :dict-key="expenditureApplicationObj.payType" />
          </span>
        </div>
        <div class="content">
          <span>经费类型：</span>
          <span>
            <DictTag :dict-list="getDictList('ExpenditureKpiFundType')" :dict-key="expenditureApplicationObj.fundType" />
          </span>
        </div>
        <div class="content">
          <span>预算总金额：</span>
          <span>￥{{ expenditureApplicationObj.amount }}</span>
        </div>
        <div class="content">
          <span>可用金额：</span>
          <span>￥{{ expenditureApplicationObj.availableAmount }}</span>
        </div>
        <div class="content">
          <span>项目负责人部门：</span>
          <span>{{ showIdLabel(organizationList, expenditureApplicationObj.organizationId, 'organizationName') }}</span>
        </div>
        <div class="content">
          <span>项目负责人：</span>
          <span>{{ showIdLabel(userList, expenditureApplicationObj.managerId, 'name') }}</span>
        </div>
        <div class="content">
          <span>功能分类：</span>
          <span>{{ showIdLabel(expenditureFunctionalList, expenditureApplicationObj.expenditureFunctionalId, 'name') }}</span>
        </div>
        <div class="content">
          <span>财政项目：</span>
          <span>{{ showIdLabel(expenditureFiscalList, expenditureApplicationObj.expenditureFiscalId, 'name') }}</span>
        </div>
        <div class="content">
          <span>指标来源：</span>
          <span>
            <DictTag :dict-list="getDictList('ExpenditureKpiSource')" :dict-key="expenditureApplicationObj.source" />
          </span>
        </div>
        <div class="content">
          <span>项目类型：</span>
          <span>{{ showIdLabel(expenditurePtypeList, expenditureApplicationObj.expenditurePtypeId, 'name') }}</span>
        </div>
        <div class="content">
          <span>指标单状态：</span>
          <span>
            <EnumTag :enum-list="getEnumList('ExpenditureKpiState')" :enum-key="expenditureApplicationObj.state" />
          </span>
        </div>
        <div class="content">
          <span>按经济分类控制金额：</span>
          <span>
            <EnumTag :enum-list="getEnumList('CommonYesNo')" :enum-key="expenditureApplicationObj.isEconomic" />
          </span>
        </div>
      </div>
    </div>
  </van-popup>
  <!-- <div class="report-form-list-content-1 aggregate" v-if="finalAvailableAmount != null"></div> -->
  <div class="aggregate">
    <div class="" v-if="finalAvailableAmount != null">最大可报账金额: ￥{{ finalAvailableAmount < 0 ? 0 : finalAvailableAmount }}</div>
    <!-- <div class="">差旅费用总计: ￥{{ totalAmount }}</div> -->
  </div>
  <div class="h5-model" v-if="kpiVisible">
    <selectKpiList :itemsVisible="kpiVisible" @close="kpiVisible = false" @expenditureKpiSelect="changeExpenditureKpi"></selectKpiList>
  </div>
  <div class="h5-model" v-if="kpiVisible1">
    <selectExpenditureApplicationList :itemsVisible="kpiVisible1" :expenditureKpiId="obj.expenditureKpiId" @close="kpiVisible1 = false" @expenditureKpiSelect="changeExpenditureApplication"></selectExpenditureApplicationList>
  </div>
</template>

<script setup>
  import { ref } from 'vue'
  import { useRoute, useRouter } from "vue-router";
  import {parseTime} from "@/utils/ruoyi";
  import {getUserId} from "@/config/cookie";
  import useUserStore from "@/store/modules/user";
  import SvgIcon from "@/components/SvgIcon/index.vue";
  import {doGet, doPost, doDownload} from '@/config/http'
  import selectKpiList from '@/h5/components/selectKpiList.vue';
  import selectExpenditureApplicationList from '@/h5/components/selectExpenditureApplicationList.vue';
  import {
    alertErrorMsg, alertWarningMsg,
    customValidator,
    getDictList,
    getEnumList, getEnv,
    getListPageSize, isNullOrUndefined, isNullOrUndefinedOrEmpty,
    notifySuccess,
    showIdLabel,
    svc
  } from "@/config/common"
  import initListStore from '@/store/modules/initList'

  const router = useRouter()
  const route = useRoute()
  let expenditureKpiDrawer = ref(false)
  let expenditureApplicationDrawer = ref(false)
  let oper = ref('')
  let id = ref('')
  let basicInfo = ref(null)
  let kpiVisible = ref(false)
  let kpiVisible1 = ref(false)
  let isShowModel = ref(false)
  let isShowModel1 = ref(false)
  let available = ref(null) //按经济分类的可用金额
  let expenditureEconomicName = ref('')
  let applicationOrganizationName = ref('')
  let applicationUserName = ref('')
  let expenditureSubjectName = ref('')
  let settlementName = ref('')
  let rulesExpenditureEconomicId = ref(false)


  let governmentList = initListStore().governmentList
  let organizationList = initListStore().organizationList
  let userList = initListStore().userList
  let expenditurePtypeList = initListStore().expenditurePtypeList//项目类型
  let expenditureFunctionalList = initListStore().expenditureFunctionalList//功能分类
  let expenditureEconomicList = initListStore().expenditureEconomicList//经济分类
  let expenditureFiscalList = initListStore().expenditureFiscalList//财政项目
  let expenditureSubjectList = initListStore().expenditureSubjectList//会计科目

  let expenditureKpiObj = ref({
    kpiCode: null, // 指标编码
    kpiName: null, // 指标名称
    kpiDate: null, // 单据日期
    year: null, // 预算年度
    payType: null, // 支出类型
    fundType: null, // 经费类型
    amount: null, // 预算总金额
    organizationId: null, // 项目负责人部门ID
    managerId: null, // 项目负责人
    expenditurePtypeId: null, // 项目类型ID
    expenditureFunctionalId: null, // 功能分类ID
    expenditureFiscalId: null, // 财政项目ID
    source: null, // 指标来源
    state: null, // 状态
    isEconomic: null, // 按经济分类控制金额
    availableAmount: null,
  })
  let expenditureApplicationObj = ref({
    applicationCode: null, // 申请单号
    applicationDate: null, // 申请日期
    applicationType: null, // 类型
    amount: null, // 申请金额
    items: null, // 请款事项
    reason: null, // 支出事由
    state: null, // 状态
    remark: null, // 备注
    availableAmount: null,
  })

  let obj = ref({
    expenditureApplicationId: null,	// 事前用款申请单ID		false
    expenditureEconomicId: null,	// 经济分类ID		false
    expenditureKpiId: null,	// 指标单表ID		false
    expenditureSubjectId: null,	// 会计科目ID		false
    reimbursementType: '0', // 报账单类型
    reimbursementCode: null,	// 报账单号		false
    reimbursementDate: parseTime(new Date().getTime(), '{y}-{m}-{d}'),	// 报账日期		false
    amount: 0,	// 金额		false
    settlement: null,	// 结算方式		false
    applicationOrganizationId: useUserStore().organization.id, // 申请人部门ID
    applicationUserId: getUserId(), // 申请人用户ID
    state: null,	// 状态		false
    approveId: null,
    id: null,	// 主键ID		false
    createBy: null,	// 创建人用户ID		false
    createTime: null,	// 创建时间		false
    updateBy: null,	// 最后修改人用户ID		false
    updateTime: null,	// 最后修改时间		false
    version: null,	// 数据版本		false

    pays: [],
    payees: [],
    itemFiles: [],
  })

  let isShowExpenditureEconomic = ref(false)
  let isShowExpenditureSubject = ref(false)
  let cascaderValue = ref(null)
  let cascaderValue1 = ref(null)
  let currentDate1 = ref(parseTime(new Date().getTime(), '{y}-{m}-{d}').split('-'))
  let isShowPickerDate = ref(false)
  let showPicker1 = ref(false)
  let showPicker2 = ref(false)
  let showPicker3 = ref(false)

  const arrChangeTreeFn = (list, pid = null, parentLevel = 0) => {
    if (!list) {
        return null
    }
    return list
    .filter((item) =>
      !pid ? item.parentId === null : item.parentId === pid
    )
    .map(item => {
      item.level = parentLevel + 1
      item.children = arrChangeTreeFn(list, item.id, parentLevel + 1);
      if(item.children.length === 0) {
        item.children = null
      }

      return item;
    });
  }

//   const initList = async () => {
//   let p1 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false)
//   let p2 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false)
//   let p3 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false)
//   let p4 = doGet(svc, '/expenditure-ptype/page', {pageSize: getListPageSize()}, false)
//   let p5 = doGet(svc, '/expenditure-functional/page', {pageSize: getListPageSize()}, false)
//   let p6 = doGet(svc, '/expenditure-economic/page', {pageSize: getListPageSize()}, false)
//   let p7 = doGet(svc, '/expenditure-fiscal/page', {pageSize: getListPageSize()}, false)
//   let p8 = doGet(svc, '/expenditure-subject/page', {pageSize: getListPageSize()}, false)
//   let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8])
//   governmentList.value = resArray[0]['records']
//   organizationList.value = resArray[1]['records']
//   userList.value = resArray[2]['records']
//   expenditurePtypeList.value = resArray[3]['records']
//   expenditureFunctionalList.value = resArray[4]['records']
//   expenditureEconomicList.value = arrChangeTreeFn(resArray[5]['records'])
//   expenditureFiscalList.value = resArray[6]['records']
//   expenditureSubjectList.value = arrChangeTreeFn(resArray[7]['records'])
// }

const emit = defineEmits(['updataBasic'])
const initObj = async () =>  {
  oper.value = route.query.oper
  id.value = null
  if (route.query.id) {
    id.value = route.query.id
    obj.value = await doGet(svc, '/expenditure-reimbursement/' + id.value, {}, true)
    emit('updataBasic', obj.value);
    console.log('obj.value----basicInfo',obj.value)
    obj.value.expenditureEconomicId = obj.value.expenditureEconomicId.split(',')
    
    obj.value.expenditureSubjectId = obj.value.expenditureSubjectId.split(',')
    // currentDate1.value = obj.value.reimbursementDate.split('-')
    if (!isNullOrUndefinedOrEmpty(obj.value.expenditureKpiId)) {
      expenditureKpiObj.value = await doGet(svc, `/expenditure-kpi/${obj.value.expenditureKpiId}`, {}, false)
      expenditureKpiObj.value.availableAmount = await doGet(svc, '/customExpenditureKpis/queryExpenditureKpiAvailableAmount', {expenditureKpiId: obj.value.expenditureKpiId}, false)
      await changeExpenditureKpi(expenditureKpiObj.value, obj.value.expenditureApplicationId)
    }
    if (!isNullOrUndefinedOrEmpty(obj.value.expenditureApplicationId)) {
      expenditureApplicationObj.value = await doGet(svc, `/expenditure-application/${obj.value.expenditureApplicationId}`, {}, false)
      expenditureApplicationObj.value.availableAmount = await doGet(svc, '/customExpenditureExpenses/queryExpenditureApplicationAvailableAmount', {expenditureApplicationId: obj.value.expenditureApplicationId}, false)
      await changeExpenditureApplication(expenditureApplicationObj.value)
    }

    if(obj.value.reimbursementDate) {
      let oDate = obj.value.reimbursementDate.split('-')
      currentDate1.value = [oDate[0], oDate[1], oDate[2]]
    }

    if(obj.value.applicationOrganizationId) {
      applicationOrganizationName.value = organizationList.filter(item => item.id === obj.value.applicationOrganizationId)[0].organizationName
    }

    if(obj.value.applicationUserId) {
      applicationUserName.value = userList.filter(item => item.id === obj.value.applicationUserId)[0].name
    }

    if(obj.value.settlement) {
      settlementName.value = getDictList('ExpenditureSettlement').filter(item => item.key === obj.value.settlement)[0].value
    }
    // 经济分类
    let expenditureEconomicName1 = await doGet(svc, '/expenditure-economic/ids', {ids: obj.value.expenditureEconomicId.join(',')}, false)
    expenditureEconomicName.value = expenditureEconomicName1.map(item => item.name).join('/')
    // 会计科目
    let expenditureSubjectName1 = await doGet(svc, '/expenditure-subject/ids', {ids: obj.value.expenditureSubjectId.join(',')}, false)
    expenditureSubjectName.value = expenditureSubjectName1.map(item => item.name).join('/')
  }
}

initObj()
// initList()

const finalAvailableAmount = computed(() => {
  if (isNullOrUndefined(expenditureKpiObj.value.availableAmount)) {
    return null
  }
  let r = expenditureKpiObj.value.availableAmount
  if (!isNullOrUndefined(expenditureApplicationObj.value.availableAmount)) {
    r = Math.min(r, expenditureApplicationObj.value.availableAmount)
  }
  if (!isNullOrUndefined(available.value)) {
    r = Math.min(r, available.value)
  }
  return r
})

const onFinish = (val) => {
  console.log('val',val)
  obj.value.expenditureEconomicId = val.selectedOptions.map(item => item.id)
  expenditureEconomicName.value = val.selectedOptions.map(item => item.name).join('/')
  let o =  obj.value.expenditureEconomicId
  if (o.length > 0) {
    let para = {
      expenditureKpiId: obj.value.expenditureKpiId,
      expenditureEconomicId: o.join(","),
      useFluctuateStr: "false",
    }
    doGet(svc, '/customExpenditureKpis/queryExpenditureKpiAvailableAmount', para, false).then(res => {
      available.value = res
      isShowExpenditureEconomic.value = false
    })
  }


}
const onFinish1 = (val) => {
  console.log('val',val)
  obj.value.expenditureSubjectId = val.selectedOptions.map(item => item.id)
  expenditureSubjectName.value = val.selectedOptions.map(item => item.name).join('/')
  isShowExpenditureSubject.value = false
}

const changeExpenditureKpi = async (data, expenditureApplicationId) => {
  expenditureKpiObj.value = data
  obj.value.expenditureKpiId = data.id

  // 重置申请单
  expenditureApplicationObj.value = {}
  obj.value.expenditureApplicationId = expenditureApplicationId
  rulesExpenditureEconomicId.value = false
  // 设置经济分类
  expenditureEconomicList.value = []
  available.value = null
  cascaderValue.value = null
  expenditureEconomicName.value = ''
  if (expenditureKpiObj.value.isEconomic === '1') {
    let expenditureKpiItemList = await doGet(svc, '/expenditure-kpi-item/listByField', {
      field: 'expenditureKpiId',
      values: obj.value.expenditureKpiId
    }, false)
    console.log('expenditureKpiItemList======',expenditureKpiItemList)
    let expenditureEconomicIds = []
    expenditureKpiItemList.map(item => {
      item.expenditureEconomicId.split(',').map(m => {
        if (!expenditureEconomicIds.includes(m)) {
          expenditureEconomicIds.push(m)
        }
      })
    })
    let expenditureEconomicList1 = await doGet(svc, '/expenditure-economic/ids', {ids: expenditureEconomicIds.join(',')}, false)
    expenditureEconomicList.value = arrChangeTreeFn(expenditureEconomicList1)
    console.log('expenditureEconomicList.value',expenditureEconomicList.value)
    rulesExpenditureEconomicId.value = true
  }
}

const changeExpenditureApplication = async (data) => {
  expenditureApplicationObj.value = data
  expenditureApplicationObj.value.availableAmount = await doGet(svc, '/customExpenditureExpenses/queryExpenditureApplicationAvailableAmount', {expenditureApplicationId: data.id}, false)
  obj.value.expenditureApplicationId = data.id
  // 设置经济分类
  if (expenditureKpiObj.value.isEconomic === '1') {
    let expenditureEconomicIds = []
    data.expenditureEconomicId.split(',').map(m => {
      if (!expenditureEconomicIds.includes(m)) {
        expenditureEconomicIds.push(m)
      }
    })
    expenditureEconomicList.value = await doGet(svc, '/expenditure-economic/ids', {ids: expenditureEconomicIds.join(',')}, false)
    rulesExpenditureEconomicId.value = true
    // rules.value.expenditureEconomicId[0].required = true
  }
}

const onConfirmDate1 = (date) => {
  console.log('date',date)
  obj.value.reimbursementDate = date.selectedValues.join('-')
  isShowPickerDate.value = false
}
const onConfirmPicker1 = (data) => {
  console.log('data',data)
  obj.value.applicationOrganizationId = data.selectedValues[0]
  applicationOrganizationName.value = data.selectedOptions[0].organizationName
  showPicker1.value = false
}
const onConfirmPicker2 = (data) => {
  console.log('data',data)
  obj.value.applicationUserId = data.selectedValues[0]
  applicationUserName.value = data.selectedOptions[0].name
  showPicker2.value = false
}
const onConfirmPicker3 = (data) => {
  console.log('data',data)
  obj.value.settlement = data.selectedValues[0]
  settlementName.value = data.selectedOptions[0].value
  showPicker3.value = false
}

async function handleValidate() {
  return await basicInfo.value.validate().catch((err)=>{return err})
}

// let basicInfoData = obj.value
// console.log('basicInfoData-basicInfo',basicInfoData)
defineExpose({
  obj,
  expenditureApplicationObj,
  handleValidate,
})

</script>
<style scoped lang="scss">
.home {

  // width: 100%;
  // height: 100vh;
  overflow: hidden;


  background: #eff2f5;;
}
.select-list {
  // width: 100%;
  margin-top: 1.25rem;
  overflow: hidden;
  background: #fff;
  margin-top: .625rem;
}
.list {
  padding: .9375rem;
  border-bottom: 1px solid #ccc;

}
.list-content {
  margin: .3125rem 0;
  & span {
    font-size: 1rem
  };
}
.btns {
  margin-top: .625rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.btn {
  margin: 0 .225rem;
}
// <div class="select-list">
//       <div class="list">
//         <div class="list-content">
//           <span>指标名称：</span>
//           <span>暂无</span>
//         </div>
//         <div class="list-content">
//           <span>可用金额：</span>
//           <span>暂无</span>
//         </div>
//       </div>
//     </div>
//   </div>
.files {
  padding: 0 .9375rem;
  background: #fff;
  .files-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .625rem 0;
    .files-head-left {
      display: flex;
      align-items: center;
    }
    & p span {
      padding-left: .9375rem;
    }
  }
  .files-list {
    li {
      padding: .625rem 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: var(--van-gray-6);
      .files-list-left {
        display: flex;
        align-items: center;
        .files-list-content {
          margin-left: 1.25rem;
          & p {
            .list-content-hindline {
              font-size: 1.125rem;
              padding-right: .9375rem;
              font-weight: bold;
              color: #000;
            }
          }
        }
      }
    }

  }
}
.model-head {
  font-size: 1.5rem;
  font-weight: bold;
  margin-top: 2rem;
  text-align: center;
}
.model-content {
  padding: 0 1.2rem;
}
.content {
  padding: .625rem 0;
  color: var(--van-gray-10);
  display: flex;
  // align-items: center;
}
.content span:nth-child(1) {
  display: inline-block;
  text-align: top;
  // width: 46%;
  min-width: 25%;
}
.aggregate {
  width: 100%;
  height: 4rem;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  justify-content: center;
  flex-direction: column;
  background: #ebe1e1;
}
.aggregate div {
  margin-left: .625rem;
}
</style>

